module.exports = {
  up: async (queryInterface, Sequelize) => {
    // 2. 表格列配置表
    await queryInterface.createTable('table_columns', {
      id: {
        type: Sequelize.UUID,
        defaultValue: Sequelize.UUIDV4,
        primaryKey: true,
      },
      table_id: {
        type: Sequelize.UUID,
        allowNull: false,
        references: {
          model: 'table_configs',
          key: 'id',
        },
        onUpdate: 'CASCADE',
        onDelete: 'CASCADE',
      },
      prop: {
        type: Sequelize.STRING(100),
        allowNull: false,
        comment: '字段名',
      },
      label: {
        type: Sequelize.STRING(100),
        allowNull: false,
        comment: '列标题',
      },
      width: {
        type: Sequelize.INTEGER,
        allowNull: true,
        comment: '列宽度',
      },
      min_width: {
        type: Sequelize.INTEGER,
        allowNull: true,
        comment: '最小宽度',
      },
      fixed: {
        type: Sequelize.ENUM('left', 'right', 'none'),
        allowNull: false,
        defaultValue: 'none',
        comment: '固定列',
      },
      sortable: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: false,
        comment: '是否可排序',
      },
      show_overflow_tooltip: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: true,
        comment: '是否显示tooltip',
      },
      align: {
        type: Sequelize.ENUM('left', 'center', 'right'),
        allowNull: false,
        defaultValue: 'left',
        comment: '对齐方式',
      },
      formatter_type: {
        type: Sequelize.STRING(50),
        allowNull: true,
        comment: '格式化类型: date, time, datetime, money, enum, custom等',
      },
      formatter_config: {
        type: Sequelize.JSON,
        allowNull: true,
        comment: '格式化配置',
      },
      is_visible: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: true,
        comment: '是否显示',
      },
      is_searchable: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: false,
        comment: '是否可搜索',
      },
      sort_order: {
        type: Sequelize.INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: '排序',
      },
      created_at: {
        type: Sequelize.DATE,
        allowNull: false,
      },
      updated_at: {
        type: Sequelize.DATE,
        allowNull: false,
      },
    });

    await queryInterface.addIndex('table_columns', ['table_id']);
    await queryInterface.addIndex('table_columns', ['is_visible']);
  },

  down: async (queryInterface) => {
    await queryInterface.dropTable('table_columns');
  },
};


